<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	
	$(":text:first").blur(function(){
		var name=$(this).val();
		if(name!=""){
			$.get("IsUserExistServlet?username="+name,function(data,status){
				if(status=="success"){
					if(data==0){
						$("#suser").html("用户名可用!");
						$("#suser").css("color","green");
					}else{
						$("#suser").html("用户名存在!")
						$("#suser").css("color","red");
					}
				}
			})
		}
	});
	

	
	$(":radio:first").click(function(){
		$("#sname").show();
		
	});
	$(":radio:eq(1)").click(function(){
		$("#sname").hide();
	});
	$(":button:first").click(function(){
		var p1=$(":password:first").val();
		var p2=$(":password:eq(1)").val();
		var p3=$('input[name="role"]:checked').val();
		var p4=$(":text:last").val();
			if(p1==""){
				alert("请输入密码");
			}else if(p1!=p2){
				p1="";
				p2="";
				alert("两次密码不一致");
			}else if(p3==0&&p4==""){
				alert("请输入店铺名称");
			}
			else{
				$("form").submit();
			}
	});
});
</script>
</head>
<body>
<form action="RegisterServlet?rolrId=">
用户名:&nbsp;<input type="text" name="username">&nbsp;<span id="suser"></span><br>
密码:&nbsp;&nbsp;<input type="password" name="password"><br>
确认密码:<input type="password" name="password2"><br>
用户昵称:<input type="text" name="nickname"><br>
手机号:&nbsp;<input type="text" name="phonenumber"><br>
真实姓名:<input type="text" name="truename"><br>
证件号:&nbsp;<input type="text" name="idnumber"><br>
商家用户:<input type="radio" name="role" value="0" checked>
普通用户:<input type="radio" name="role" value="1" ><br>
<span id="sname" >
店铺名称:<input type="text" name="shopname"><br>
</span>
<input type="button" value="注册"> 
</form>
</body>
</html>